﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chefbook.DataObjects;
using System.Globalization;
using Chefbook.ViewModels;

namespace Chefbook.UserActions
{
    /// <summary>
    /// An action to remove a recipe from a category
    /// </summary>
    public class RemoveRecipeFromCategoryAction : UserActionBase
    {
        private RecipeViewModel recipeToRemove;
        private CategoryViewModel categoryToRemoveFrom;

        /// <summary>
        /// Creates a new action to remove a recipe from a category
        /// </summary>
        /// <param name="recipeToRemove">The recipe to removee</param>
        /// <param name="categoryToRemoveFrom">The category to remove from</param>
        public RemoveRecipeFromCategoryAction(RecipeViewModel recipeToRemove, CategoryViewModel categoryToRemoveFrom):base()
        {
            this.recipeToRemove = recipeToRemove;
            this.categoryToRemoveFrom = categoryToRemoveFrom;
        }

        /// <summary>
        /// Removes the recipe from the specified category
        /// </summary>
        public override void DoAction()
        {
            base.DoAction();
            categoryToRemoveFrom.RemoveRecipe(recipeToRemove);
        }

        /// <summary>
        /// Returns the recipe to the category it was removed from
        /// </summary>
        public override void UndoAction()
        {
            base.UndoAction();
            categoryToRemoveFrom.AddRecipe(recipeToRemove);
        }

        /// <summary>
        /// Returns a user-friendly string describing the action
        /// </summary>
        /// <returns>A user-friendly string describing the action</returns>
        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentUICulture, "Remove Recipe '{0}' from Category '{1}'", recipeToRemove, categoryToRemoveFrom);
        }
    }
}
